<?php


namespace App\AppContext;

use Illuminate\Support\Facades\Cache;

/**
 * API
 * Class Api
 * @package App\AppContext
 */
class Api extends Base
{
    function __construct()
    {
        $request = request();
        $this->token = $request->header('token', '');
        if (empty($this->token) || $this->token == 'null') {
            $this->token = md5(uniqid('api', true));
        }
    }

    function appId(): int
    {
        return 2;
    }

    function appName(): string
    {
        return 'API';
    }

    function all(): array
    {
        return Cache::get($this->token, []);
    }

    function save(array $value): void
    {
        Cache::put($this->token, $value, 7 * 24 * 60 * 60);
    }

    function getToken(): string
    {
        return $this->token;
    }

    function destroy(): void
    {
        Cache::forget($this->token);
    }

    private $token;
}
